package org.bookie.framework.components;

import java.util.ArrayList;
import java.util.List;

/**
 * {@link MenuItem} associates name of the page with the key for the name of the
 * page in the menu
 * 
 * @author drobiazko
 * 
 */
public class MenuItem {
	private final String page;
	private final String key;
	private final List<MenuItem> children = new ArrayList<MenuItem>();

	/**
	 * Default constructor
	 * 
	 * @param page
	 * @param key
	 */
	public MenuItem(String page, String key) {
		this.page = page;
		this.key = key;
	}

	/**
	 * Special method for better looking builder
	 * 
	 * @param child
	 * @return
	 */
	public MenuItem add(MenuItem child) {
		children.add(child);
		return this;
	}

	public List<MenuItem> getChildren() {
		return children;
	}

	public String getKey() {
		return key;
	}

	public String getPage() {
		return page;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer("MenuItem[");
		sb.append("page=" + getPage());
		sb.append(",key=" + getKey());
		sb.append(",children=" + getChildren().size());
		sb.append("]");
		return sb.toString();
	}
}
